package com.wxzz.elearing.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wxzz.elearing.user.entity.WxUserStatistics;
import com.wxzz.elearing.user.entity.WxUserSystemMessage;
import com.wxzz.elearing.user.vo.VisitNumVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface WxUserStatisticsMapper extends BaseMapper<WxUserStatistics> {

    /**
     * 根据企业id查询访问人数
     *
     * @param enterpriseId
     * @param startTime
     * @param endTime
     * @return
     */
    @Select("SELECT\n" +
            "\tSUM( visit_num ) visitNum,save_time saveTime\n" +
            "FROM\n" +
            "\twx_user_statistics \n" +
            "WHERE\n" +
            "save_time BETWEEN #{startTime} AND #{endTime}\n" +
            "AND\n" +
            "\tenterprise_id = #{enterpriseId} \n" +
            "\tAND deleted = 0 \n" +
            "GROUP BY\n" +
            "\tsave_time \n" +
            "ORDER BY\n" +
            "\tsave_time DESC")
    List<VisitNumVo> selectVisitNumByEnterpriseId(@Param("enterpriseId") Long enterpriseId, @Param("startTime") String startTime, @Param("endTime") String endTime);

    /**
     * 查询所有企业访问人数
     *
     * @param startTime
     * @param endTime
     * @return
     */
    @Select("SELECT\n" +
            "\tSUM( visit_num ) visitNum,save_time saveTime\n" +
            "FROM\n" +
            "\twx_user_statistics \n" +
            "WHERE\n" +
            "save_time BETWEEN #{startTime} AND #{endTime}\n" +
            "AND\n" +
            "\tenterprise_id !=0 \n" +
            "\tAND deleted = 0 \n" +
            "GROUP BY\n" +
            "\tsave_time \n" +
            "ORDER BY\n" +
            "\tsave_time DESC")
    List<VisitNumVo> selectVisitNumByEnterprise(@Param("startTime") String startTime, @Param("endTime") String endTime);

    /**
     * 查询所有访问人数
     *
     * @param startTime
     * @param endTime
     * @return
     */
    @Select("SELECT\n" +
            "\tSUM( visit_num ) visitNum,\n" +
            "\tsave_time saveTime \n" +
            "FROM\n" +
            "\twx_user_statistics \n" +
            "WHERE\n" +
            "\tsave_time BETWEEN #{startTime} \n" +
            "\tAND #{endTime} \n" +
            "\tAND deleted = 0 \n" +
            "GROUP BY\n" +
            "\tsave_time \n" +
            "ORDER BY\n" +
            "\tsave_time DESC")
    List<VisitNumVo> selectAllVisitNum(@Param("startTime") String startTime, @Param("endTime") String endTime);

    @Select("SELECT\n" +
            "\tSUM( visit_num ) visitNum \n" +
            "FROM\n" +
            "\twx_user_statistics \n" +
            "WHERE\n" +
            "\tsave_time BETWEEN #{startTime} \n" +
            "\tAND #{endTime} \n" +
            "\tAND deleted = 0 \n" +
            "\tAND enterprise_id !=0")
    Long countEnterpriseVisitNum(@Param("startTime") String startTime, @Param("endTime") String endTime);

    @Select("SELECT\n" +
            "\tSUM( visit_num ) visitNum \n" +
            "FROM\n" +
            "\twx_user_statistics \n" +
            "WHERE\n" +
            "\tsave_time BETWEEN #{startTime} \n" +
            "\tAND #{endTime} \n" +
            "\tAND deleted = 0 ")
    Long countAllVisitNum(@Param("startTime") String startTime, @Param("endTime") String endTime);

    @Select("SELECT\n" +
            "\tSUM( visit_num ) visitNum \n" +
            "FROM\n" +
            "\twx_user_statistics \n" +
            "WHERE\n" +
            "\tsave_time BETWEEN #{startTime} \n" +
            "\tAND #{endTime} \n" +
            "\tAND deleted = 0 \n" +
            "\tAND enterprise_id =#{enterpriseId}")
    Long countEnterpriseVisitNumById(@Param("enterpriseId") Long enterpriseId, @Param("startTime") String startTime, @Param("endTime") String endTime);

    @Select("SELECT\n" +
            "\tSUM( visit_num ) visitNum,\n" +
            "\tsave_time \n" +
            "FROM\n" +
            "\t`wx_user_statistics` \n" +
            "WHERE\n" +
            "\tenterprise_id = #{enterpriseId} \n" +
            "\tAND deleted = 0 \n" +
            "\tAND save_time BETWEEN #{startTime} \n" +
            "\tAND #{endTime} \n" +
            "GROUP BY\n" +
            "\tsave_time \n" +
            "ORDER BY\n" +
            "\tsave_time DESC")
    List<VisitNumVo> selectEnterpriseWxUserVisitNumStatisticsVo(@Param("enterpriseId") Long enterpriseId, @Param("startTime") String startTime, @Param("endTime") String endTime);
}
